package com.tunis.gtug.client;

import com.extjs.gxt.charts.client.Chart;
import com.extjs.gxt.charts.client.model.ChartModel;
import com.extjs.gxt.charts.client.model.Legend;
import com.extjs.gxt.charts.client.model.Legend.Position;
import com.extjs.gxt.charts.client.model.charts.PieChart;
import com.extjs.gxt.ui.client.fx.FxConfig;
import com.extjs.gxt.ui.client.util.Rectangle;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.Element;

public class ChartContent extends LayoutContainer {

	private ContentPanel contentPanel;

	public ContentPanel getContentPanel() {
		return contentPanel;
	}

	@Override
	protected void onRender(Element parent, int index) {
		// TODO Auto-generated method stub
		super.onRender(parent, index);
		contentPanel = new ContentPanel();
		contentPanel.setSize(600, 300);
		contentPanel.setFrame(true);
		contentPanel.setSize(400, 400);
		contentPanel.setLayout(new FitLayout());
		String url = "ExtGWT/chart/open-flash-chart.swf";
		Chart chart = new Chart(url);

		chart.setChartModel(getMyChartModel());
		contentPanel.add(chart);

		add(contentPanel);

	}

	private ChartModel getMyChartModel() {

		ChartModel cm = new ChartModel(
				"Pourcentage des membres suivant leur occupation");
		cm.setBackgroundColour("#fffff5");
		Legend lg = new Legend(Position.RIGHT, true);
		lg.setPadding(10);
		cm.setLegend(lg);
		PieChart pie = new PieChart();
		// pie.setAlpha(0.5f);
		pie.setNoLabels(true);
		pie.setTooltip("#label# #val#<br>#percent#");
		pie.setColours("#ff0000", "#00aa00");
		pie.addSlices(new PieChart.Slice(5, "Software Engineer"));
		pie.addSlices(new PieChart.Slice(9, "Student"));
		cm.addChartConfig(pie);
		return cm;
	}

}
